<?php
session_start();

/*
 * 
 * template name: Detail Deal
 * Wiew detail of Deal
 * @author:Tham
 * * 
 */

$sucessful = 0;
$id_deal = -1;
$aImage = array();
if (isset($_REQUEST['i'])) {

    $id_deal = $_REQUEST['i'];
}
if (isset($_REQUEST['booking'])) {
    if ($_SESSION['userlogin'] == "") {

        include_once 'detaildeal/login.php';
        include_once 'detaildeal/resgister.php';
    } else {

        $data['user_book'] = $_SESSION['userlogin']['ID'];
        $data['deal_flight_id'] = $id_deal;
        $data['type_travel'] = DealFlight::DEAL;
        $dschek = BookingDeal::checkBookDeal($data);
        $countdscheck = $dschek[0]->totalrows;
        if ($countdscheck == 0) {
            BookingDeal::AddBookingDeal($data);
            $sucessful = 1;
        }
        ?>
        deal-flight-id="<?php echo $id_deal; ?>"
        <?php
        //print_r($data);
    }
}



/*
 * get list deal  
 */
$listinfoDeal = DealFlight::getInfoDealFlightByDealFlightID($id_deal, DealFlight::DEAL);
if($listinfoDeal){
    $aImage = unserialize($listinfoDeal[0]->image);
}else{
    redirectTo404Page();
}
//print_r($listinfoDeal);

get_header();
?>
<style>
    #slider .hslide {
	width: 673px;
	height: 393px;
    }
    
</style>
<div class="content">
    <div class="container">
        <div class="box-main">
            <div class="row">
                <div class="col-md-9">

                    <div class="tab">
                        <a href="<?php echo get_site_url(); ?>">Home / </a> <?php echo $listinfoDeal[0]->name_deal; ?> </div>
                    <h2><?php echo $listinfoDeal[0]->name_deal; ?></h2>
                    <hr/>
                    <br/>

                <div class="text-content">
			<div id="sitewrapper">
			    <section class="sliderwrapper">
				<div id="slider" data-speed="500" data-easing="swing" data-duration="2000"> 
				    <ul>
					<?php 
					$idSlider = 0;
					foreach($aImage as $img){?>
					<li class="hslide" data-id="hashslider<?php echo $idSlider; ?>">
					    <div>
						<img src="<?php echo DEAL_URL.$img?>"/>
					    </div>
					</li>
					<?php 
					$idSlider++;
					}?>
				    </ul>
				</div>			
				<?php /*
				<div class="pagination detail-paginate-slide"><div id="numbers"></div></div>
				 * 
				 */?>
				<a class="button next-slider-detail" id="back"></a>
				<a class="button prev-slider-detail" id="next"></a>
			    </section>
			 </div>
                        <br clear="all" />
                        <p  class="text_gray"><br/>Update date :<?php echo date('d M Y', $listinfoDeal[0]->create_time); ?></p>
                        <hr>
                        <div>
                            <table>
                                <tr><td>
                                        <?php
                                        $description = $listinfoDeal[0]->description;
                                        $description = str_replace('<!--more-->', " ", $description);
                                        echo $description;
                                        ?>
                                    </td></tr>
                            </table>

                        </div>
                        <div><br/><button name="booking" type="button" id="booking" class="button request-deal-flight">Request a Deal</button></div>




                    </div>

                </div>
                <?php
                include_once 'right_single.php';
                ?>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript" language="javascript" src="<?php bloginfo('template_directory') ?>/js/bootstrap.js"></script>

<?php get_footer();
?>


<script type="text/javascript">



    jQuery(document).ready(function() {
        jQuery("#booking-false").modal();
        //jQuery("#booking-success").modal();

        jQuery('.request-deal-flight').click(function() {
            // alert("a");
            jQuery('#request-deal-flight-form').modal();
        });
        jQuery("#bt_creatRegisterPopup").click(function() {

            url_ajax = jQuery("#url_ajax").val();
            var name = document.getElementById('txt_name').value;
            var name = name.trim();
            var name2 = document.getElementById('txt_lastname').value;
            name2 = name2.trim();
            var email = document.getElementById('txt_email2').value;
            email = email.trim();
            var password = document.getElementById('txt_password2').value;
            password = password.trim();
            var repassword = document.getElementById('txt_repassword').value;
            repassword = repassword.trim();
            var username = document.getElementById('txt_username').value;
            username = username.trim();
            bool = 0;

            if (name == "") {
                document.getElementById('error_name').innerHTML = "Please fill in your First Name";

                bool = 1;
            }
            else {
                document.getElementById('error_name').innerHTML = "";
            }

            if (name2 == "") {
                document.getElementById('error_lastname').innerHTML = "Please fill in your Last Name";
                bool = 1;
            }
            else {
                document.getElementById('error_lastname').innerHTML = "";
            }
            if (email == "") {
                document.getElementById('error_email').innerHTML = "Please fill in your Email";
                bool = 1;
            }

            else if (validateEmail(email) == false) {
                document.getElementById('error_email').innerHTML = "Email is not a valid e-mail address";
                bool = 1;
            }
            else {

                $.post(url_ajax, {emailexist: email}, function(data) {

                    if (data == 1)
                    {
                        document.getElementById('error_email').innerHTML = "Email have already exist";
                        bool = 1;
                    }
                    else
                    {
                        document.getElementById('error_email').innerHTML = "";

                    }
                });

            }
            if (password == "") {
                document.getElementById('error_passw').innerHTML = "Please fill in your Password";
                bool = 1;
            }
            else {
                document.getElementById('error_passw').innerHTML = "";
            }
            if (repassword == "") {
                document.getElementById('error_repassw').innerHTML = "Please fill in your Re Password";
                bool = 1;
            }
            else if (repassword != password) {
                document.getElementById('error_repassw').innerHTML = "Password and  Re Password is not the same";
                bool = 1;
            }
            else {
                document.getElementById('error_repassw').innerHTML = "";

            }
            var city = jQuery("#txt_city").val();
            city = city.trim();
            if (city == "") {

                jQuery("#error_city").html("Please fill in your city");
                bool = 1;
            } else {
                jQuery("#error_city").html("");
            }

            var state = jQuery("#state").val();
            if (state == "") {

                jQuery("#error_state").html("Please fill in your state");
                bool = 1;
            }
            else {
                jQuery("#error_state").html("");
            }
            var postcode = jQuery("#txt_postcode").val();
            postcode = postcode.trim();
            if (postcode == "") {
                jQuery("#error_postcode").html("Please fill in your Postcode");
                bool = 1;
            }
            else {
                jQuery("#error_postcode").html("");
            }
            var country = jQuery("#select_country").val();
            if (bool == 0)
            {
                var site_url = jQuery("#site_url").val();
                var url_ajax = site_url + "/wp-content/themes/travel_donald/ajax/register-detail-deal.php";

                $.post(url_ajax, {name: name, lastname: name2, email: email, password: password, city: city, state: state, postcode: postcode, country: country}, function(data) {

                    // alert(data);

                    if (data == 1)
                    {

                        jQuery("#infor_reponse_sucess1").show();
                        jQuery("#infor_reponse_sucess2").hide();
                    }
                    else
                    {
                        jQuery("#infor_reponse_sucess2").show();
                        jQuery("#infor_reponse_sucess1").hide();

                    }
                });
            }
        });

    });

    jQuery('#bt_registerpopup').click(function() {
        jQuery('#booking-false').modal('hide');
        jQuery('#booking-false_register').modal();
    });
    jQuery('#comebacklogin').click(function() {
        jQuery('#booking-false_register').modal('hide');
        jQuery('#booking-false').modal();
    });
    /*
     * Check login in popup on detail deals
     * @returns none
     * 
     */
    jQuery('#bt_loginpopup').click(function() {

        var site_url = jQuery("#site_url").val();
        var url_ajax = site_url + "/wp-content/themes/travel_donald/ajax/login-detail-deal.php";
        bool = 0;
        var email = document.getElementById('txt_email').value;
        email = email.trim();
        var password = document.getElementById('txt_password').value;
        password = password.trim();
        if (email == "") {
            document.getElementById('error_email').innerHTML = "Please fill in your User Name";
            bool = 1;
        }
        else if (validText(email) == false)
        {
            document.getElementById('error_email').innerHTML = "Please enter valid characters";
            bool = 1;
        }
        else {
            document.getElementById('error_email').innerHTML = "";
        }

        if (password == "") {
            document.getElementById('error_passw').innerHTML = "Please fill in your Password";
            bool = 1;
        }
        else {
            document.getElementById('error_passw').innerHTML = "";
        }

        if (bool == 0)
        {
            $.post(url_ajax, {logout: 1, email: email, pass: password}, function(data) {
                jQuery("#info_login").html(data);
                if (data == '<span style="color:green;">Login is sucessfull</span>')
                {
                    jQuery('#booking-false').modal('hide');
                }
            });
        }



    });



</script>

<div class="modal fade" id="booking-success" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post" class="frm_register">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>                            
                </div>
                <div class="modal-body">                            
                    <div class="alert alert-success">You have requested successfully</div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="modal fade" id="request-deal-flight-form" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post" class="frm_register frm_request_deal">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Request a Deal </h4>
                </div>
                <div class="modal-body">                            
                    <table>
                        <tr>
                            <td class="td_table">Name</td>
                            <td><input class="full-name-request-deal-flight" type="text"/>
                                <span class="error-name-deal-booking error" ></span>
                            </td>
                        </tr>
                        <tr>
                            <td>Email</td>
                            <td>
                                <input class="email-deal-request-deal-flight" type="text"/>
                                <span class="error-email-deal-booking error" ></span>
                            </td>
                        </tr>
                        <tr>
                            <td>Phone</td>
                            <td><input id="phone-deal-request-deal-flight" type="text"/>
                               <span class="error-phone-deal-booking error" ></span>
                            </td>
                        </tr>
			<tr>
                            <td>Address</td>
                            <td><input id="address-deal-request-deal-flight" type="text"/>
                               <span class="error-address-deal-booking error" ></span>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <input type="hidden" value="<?php echo $id_deal ?>"/>
                                <a class="button request-deal-flight-btn" href="javascript:void(0)">Request</a>
                            </td>				    
                        </tr>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </form>
        </div>
    </div>
</div>
<input type="hidden" id="id-deal-flight" name="id-deal-flight" value="<?php echo $id_deal; ?>" />